<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="../css/loginn.css" />
    <script src="../js/jquery-3.6.0.min.js"></script>
    <script src="../js/interface.js"></script>
    <script src="../js/cookie.js"></script>
  </head>

  <body>
    <!-- 引入公共头部 -->
    <div class="header"></div>
    <script type="text/javascript">
      $(".header").load("common/head.html");
    </script>

    <!-- 登录 -->
    <div class="login">
      <div class="log">
        <div class="log-left">
          <h2>你好</h2>
          <p>欢迎管理员登录</p>
          <a href="#"><img src="../images/login-code.jpg" alt="" /></a>
          <p>匹克官方网店微信公众号</p>
          <p>关注不一样的运动商城</p>
        </div>
        <div class="log-right">
          <h2>登录你的管理员账号</h2>
          <p>
            <input type="text" id="username" placeholder="请输入用户名" />
            <span id="user_span"></span>
          </p>
          <p>
            <input type="password" id="pwd" placeholder="请输入密码" />
            <span id="pwd_span"></span>
          </p>
          <div id="btn"><a href="javascript:;">登录</a></div>
        </div>
      </div>
    </div>
    <footer></footer>
    <script>
      $("footer").load(`common/footer.html`);
    </script>
  </body>

  <script>
    // $(document).on("click", ".searchBtn", function () {
    //   type = $(".searchCon").val();
    //   window.location.href = `./goodsList.html?type=${type}`;
    // });
    //登录
    $("#btn").on("click", async function () {
      var username = $("#username").val();
      var pwd = $("#pwd").val();
      console.log(username, pwd);
      if (username && pwd) {
        var result = await myadmin({ username, pwd });
        var { status, msg } = result;
        if (status) {
          console.log(111);
          location.href = "./addproduct.html";
        } else {
          $("#pwd_span").text(msg);
          $("#pwd_span").addClass("err");
        }
      }
    });
  </script>
</html>
